using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AudioManager : MonoBehaviour
{
    public static AudioManager instance;

    private AudioSource bgm;
    private AudioSource sound;
    private AudioClip   soundClip;

    private void Awake()
    {
        instance  = this;
        bgm       = transform.Find("BGM").GetComponent<AudioSource>();
        sound     = transform.Find("Merge").GetComponent<AudioSource>();
        soundClip = sound.clip;
        
        //获取到保存声音的大小
        bgm.volume   = PlayerPrefs.GetFloat(Const.BGM,   0.5f);
        sound.volume = PlayerPrefs.GetFloat(Const.SOUND, 0.5f);
    }

    public void PlayBgm(AudioClip audioClip)
    {
        bgm.clip = audioClip;
        bgm.loop = true;
        bgm.Play();
    }
    
    public void PlaySound()
    {
        sound.PlayOneShot(soundClip);
    }

    public void OnBgmVolumeChange(float value)
    {
        bgm.volume = value;
    }
    
    public void OnSoundVolumeChange(float value)
    {
        sound.volume = value;
    }
    
}
